import unittest
from flask import Flask
from flask_testing import TestCase
import app


class FlaskAppTestCase(TestCase):

    def create_app(self):
        app.app.config['TESTING'] = True
        app.app.config['WTF_CSRF_ENABLED'] = False
        app.app.config['DEBUG'] = False
        return app.app

    def test_index_page(self):
        response = self.client.get('/')
        self.assertEqual(response.status_code, 200)
        self.assert_template_used('home.html')

    def test_prediction_page_get(self):
        response = self.client.get('/predict')
        self.assertEqual(response.status_code, 200)

    def test_prediction_page_post(self):
        with open('test_image.png', 'rb') as img:
            img_data = {
                'file': (img, 'test_image.png')
            }
            response = self.client.post('/predict', data=img_data)
            self.assertEqual(response.status_code, 200)
            self.assert_template_used('predict.html')


if __name__ == '__main__':
    unittest.main()
